package com.it.Mapper;

import com.it.pojo.Passenger;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PassengerMapper {
    @Select("select distinct i.idNumber,name,sex,phone from identity i,bind where username=#{username} and i.idNumber=bind.idNumber")
    List<Passenger> getPassenger(String username);

    @Insert("insert into identity (idNumber, name, sex, phone) values (#{passenger.idNumber},#{passenger.name},#{passenger.sex},#{passenger.phone})")
    void addPassenger(Passenger passenger, String username);

    @Insert("insert into bind (username, idNumber, isPerson) values (#{username},#{passenger.idNumber},0);")
    void addBind(Passenger passenger, String username);

    @Delete("delete from bind where idNumber=#{idNumber};")
    void deletePassenger(String idNumber);

    @Select("select idNumber, name, sex, phone from identity where idNumber=#{idNumber};")
    Passenger getPassengerById(String idNumber);

    void updatePassenger(Passenger passenger);

    @Select("select i.idNumber,name,sex,phone from bind b,identity i where b.idNumber=i.idNumber and username=#{username} and isPerson=1")
    Passenger getIdentity(String username);
}
